package com.edata.bigdata.viewmain;

import com.edata.bigdata.basic.Manager;
import com.edata.bigdata.entity.Workspace;
import com.edata.bigdata.spark.PgConnector;
import com.edata.bigdata.spark.PgWriter;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.RowFactory;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

public class PgWrite {
    public static void main(String[] args) {
        Manager manager = new Manager();
        manager.APPNAME = "PGWriteTesting";
        manager.MASTER = "local[*]";
        manager.createSparkSession();

        PgConnector connector = new PgConnector();
        connector.JDBC_IP="172.16.11.117";
        connector.JDBC_PORT="5432";
        connector.JDBC_DATABASE = "elearning";
        connector.JDBC_USER="postgres";
        connector.JDBC_PASSWORD="123456";

        PgWriter pgWriter = new PgWriter(manager.SPARKSESSION);
        pgWriter.connector = connector;
        String workspaceId1 = UUID.randomUUID().toString();
        String workspaceId2 = UUID.randomUUID().toString();
        String workspaceId3 = UUID.randomUUID().toString();
        List<Row> datas = Arrays.asList(
                RowFactory.create(workspaceId1,"terraria_1","/app/datas/"+workspaceId1),
                RowFactory.create(workspaceId2,"terraria_2","/app/datas/"+workspaceId2),
                RowFactory.create(workspaceId3,"terraria_3","/app/datas/"+workspaceId3)
        );
        pgWriter.insert(datas, Workspace.class);
        manager.stop();
    }
}
